package avicit.bdp.dgs.standard.service;

import avicit.bdp.common.base.BaseService;
import avicit.bdp.dgs.standard.DataElementEvaluateTaskResultDTO;
import avicit.bdp.dgs.standard.dao.DataElementEvaluateTaskResultDao;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.core.rest.msg.QueryRespBean;
import com.github.pagehelper.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 数据标准评估任务结果服务层
 *
 * @author mayi
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DataElementEvaluateTaskResultService
    extends BaseService<DataElementEvaluateTaskResultDao, DataElementEvaluateTaskResultDTO> {

  @Transactional(readOnly = true)
  public QueryRespBean<DataElementEvaluateTaskResultDTO> getPageList(
      String taskInstanceId, String keyWords, Integer pageNo, Integer pageSize) throws Exception {

    QueryRespBean<DataElementEvaluateTaskResultDTO> queryRespBean = new QueryRespBean<>();
    com.github.pagehelper.PageHelper.startPage(pageNo, pageSize);
    Page<DataElementEvaluateTaskResultDTO> pageResult =
        this.mapper.getPageList(taskInstanceId, keyWords);
    queryRespBean.setResult(pageResult);
    return queryRespBean;
  }

  public String save(DataElementEvaluateTaskResultDTO dto) {

    if (StringUtils.isEmpty(dto.getId())) {
      dto.setId(ComUtil.getId());
    }

    this.insert(dto);
    log4Insert(dto);

    return dto.getId();
  }
}
